package com.lkqandzzy.util;

import com.lkqandzzy.entity.User;
import com.lkqandzzy.mapper.RankMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

/**
 * @author 邹靓仔
 * @date 2020/5/28 -21:42 -blog
 **/
@Component
public class HostHolder {

    private User user;

    @Autowired
    private RankMapper rankMapper;

    public User getUser() {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        user=rankMapper.getUserByUsername(((UserDetails) principal).getUsername());
        return user;
    }



}
